import { NoSkinCellRenderer } from "../../common/item/NoSkinCellRenderer";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { PetIslandFightObserveVo } from "../vo/PetIslandFightObserveVo";
import { DisplayUtil } from "../../../../common/DisplayUtil";
import { Language } from "../../../../../extend/language/Language";
import { SRobIslandFightingInfo } from "../../../../../Message/Game/SRobIslandFightingInfo";
import { GameDefConfig } from "../../../resource/GameDefConfig";
import { PetIslandUtil } from "../PetIslandUtil";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { ObjCreate } from "../../common/ObjCreate";
import { ResFileConst } from "../../../resource/ResFileConst";
import { SecTimerView } from "../../common/SecTimerView";
import { FilterConst } from "../../../../component/gconst/FilterConst";
import { ImagesConst } from "../../../resource/ImagesConst";
import { GTextFiled } from "../../../../../com/mui/controls/GTextFiled";
type int = number;
//class PetIslandSituationInfoItemRenderer
    
    export  class PetIslandSituationInfoItemRenderer extends NoSkinCellRenderer
    {
        constructor()
        {
            super();
            return;
        }

        /* internal  */onOperateHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.PetIslandGarrison, this._vo.placeId));
            return;
        }

        /* internal  */onObserveHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=null;
            if (this._leftTime > 0) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.PetIslandFightListReq, this._vo.placeId));
            }
            else 
            {
                loc1 = new PetIslandFightObserveVo();
                loc1.placeId = this._vo.placeId;
                loc1.isObserve = true;
                Dispatcher.dispatchEvent(new DataEvent(EventName.PetIslandFightObserve, loc1));
            }
            return;
        }

        /* internal  */onPositionHandler(arg1: Object /* flash.events.TextEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.PetIslandMapShowByPosition, this._vo.pos));
            return;
        }

        /* internal  */onSecViewTimeChange(arg1: DataEvent): void
        {
            this._leftTime = int(arg1.data);
            if (this._leftTime <= 0) 
            {
                this._tfLeftTime.stop();
                DisplayUtil.removeMe(this._tfLeftTime);
                this.addChild(this._state);
                this._state.text = Language.getString(28200);
            }
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            super.data = arg1;
            if (typeof arg1 === "srobislandfightinginfo") 
            {
                this._vo = arg1 as SRobIslandFightingInfo;
                this._name.text = this._vo.attackGuildName;
                this._position.htmlText = Language.getStringByParam(28126, GameDefConfig.instance.getPetIslandName(this._vo.pos.isLand), this._vo.pos.x * PetIslandUtil.MAP_SIZE, this._vo.pos.y * PetIslandUtil.MAP_SIZE);
                this._defendName.text = this._vo.defenseGuildName;
                if (this._vo.startSeconds > 0) 
                {
                    DisplayUtil.removeMe(this._state);
                    this.addChild(this._tfLeftTime);
                    this._tfLeftTime.setLeftTime(this._vo.startSeconds);
                }
                else 
                {
                    this._tfLeftTime.stop();
                    DisplayUtil.removeMe(this._tfLeftTime);
                    this.addChild(this._state);
                    this._state.text = Language.getString(28200);
                }
            }
            return;
        }

        protected /* override */ createChildren(): void
        {
            super.createChildren();
            var loc1=GlobalStyle.setTextFormatAlign(GlobalStyle._textFormat2, flash.text.TextFormatAlign.CENTER);
            this._name = ObjCreate.createGTextField("", 0, 8, 110, 20, this, GlobalStyle.setTextFormatAlign(GlobalStyle._textFormat1, flash.text.TextFormatAlign.CENTER));
            this._name.mouseEnabled = false;
            this._position = ObjCreate.createGTextField("", 110, 8, 130, 20, this, loc1);
            this._position.addEventListener(flash.events.TextEvent.LINK, this.onPositionHandler);
            this._defendName = ObjCreate.createGTextField("", 240, 8, 110, 20, this, loc1);
            this._defendName.mouseEnabled = false;
            this._state = ObjCreate.createGTextField("", 350, 8, 110, 20, this, GlobalStyle.setTextFormatAlign(GlobalStyle._textFormat5, flash.text.TextFormatAlign.CENTER));
            this._state.mouseEnabled = false;
            var loc2=ObjCreate.createGButton(Language.getString(28143), 460, 5, 49, 24, this);
            loc2.addEventListener(flash.events.MouseEvent.CLICK, this.onOperateHandler);
            var loc3=ObjCreate.createGLoadedButton(ResFileConst.PetIslandEyeBtn, 517, 7, 29, 18, this);
            loc3.addEventListener(flash.events.MouseEvent.CLICK, this.onObserveHandler);
            this._tfLeftTime = new SecTimerView();
            this._tfLeftTime.setParse(Language.getString(28199));
            this._tfLeftTime.defaultTextFormat = GlobalStyle.setTextFormatAlign(GlobalStyle._textFormat5, flash.text.TextFormatAlign.CENTER);
            this._tfLeftTime.filters = [FilterConst.glowFilter];
            this._tfLeftTime.addEventListener(EventName.SecViewTimeChange, this.onSecViewTimeChange);
            ObjCreate.setObjAttri(this._tfLeftTime, 350, 5, 110, 20);
            ObjCreate.createBg(0, 30, 550, 2, this, ImagesConst.SplitLine);
            return;
        }

        /* internal */ /* var */_tfLeftTime: SecTimerView;

        /* internal */ /* var */_name: GTextFiled;

        /* internal */ /* var */_position: GTextFiled;

        /* internal */ /* var */_defendName: GTextFiled;

        /* internal */ /* var */_state: GTextFiled;

        /* internal */ /* var */_vo: SRobIslandFightingInfo;

        /* internal */ /* var */_leftTime: int;
    }
